package com.haixiaoke.saas.manage.ad.controller;

import com.haixiaoke.saas.ad.domain.ApartmentAd;
import com.haixiaoke.saas.ad.service.IApartmentAdService;
import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 公寓广告Controller
 *
 * @author qixi
 * @date 2024-04-26
 */
@RestController
@RequestMapping("/manage/ad/apartment")
public class ManageApartmentAdController extends BaseController {
    @Autowired
    private IApartmentAdService apartmentAdService;

    /**
     * 查询公寓广告列表
     */
    @PreAuthorize("@ss.hasPermi('ad:apartment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApartmentAd apartmentAd) {
        startPage();
        List<ApartmentAd> list = apartmentAdService.selectApartmentAdList(apartmentAd);
        return getDataTable(list);
    }

    /**
     * 导出公寓广告列表
     */
    @PreAuthorize("@ss.hasPermi('front:ad:export')")
    @Log(title = "公寓广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApartmentAd apartmentAd) {
        List<ApartmentAd> list = apartmentAdService.selectApartmentAdList(apartmentAd);
        ExcelUtil<ApartmentAd> util = new ExcelUtil<ApartmentAd>(ApartmentAd.class);
        util.exportExcel(response, list, "公寓广告数据");
    }

    /**
     * 获取公寓广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('ad:apartment:query')")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId) {
        return success(apartmentAdService.selectApartmentAdByBannerId(bannerId));
    }

    /**
     * 新增公寓广告
     */
    @PreAuthorize("@ss.hasPermi('ad:apartment:add')")
    @Log(title = "公寓广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApartmentAd apartmentAd) {
        return toAjax(apartmentAdService.insertApartmentAd(apartmentAd));
    }

    /**
     * 修改公寓广告
     */
    @PreAuthorize("@ss.hasPermi('ad:apartment:edit')")
    @Log(title = "公寓广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApartmentAd apartmentAd) {
        return toAjax(apartmentAdService.updateApartmentAd(apartmentAd));
    }

    /**
     * 删除公寓广告
     */
    @PreAuthorize("@ss.hasPermi('ad:apartment:remove')")
    @Log(title = "公寓广告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds) {
        return toAjax(apartmentAdService.deleteApartmentAdByBannerIds(bannerIds));
    }
}
